home *** CD-ROM | disk | FTP | other *** search
- From: jpochma@polyslo.UUCP (John Hoyt Pochmara)
- Newsgroups: comp.sources.misc
- Subject: v02i056: spaceout - X11 animated space display
- Message-ID: <7239@ncoast.UUCP>
- Date: 18 Feb 88 02:31:47 GMT
- Approved: allbery@ncoast.UUCP
-
- Comp.sources.misc: Volume 2, Issue 56
- Submitted-By: "John Hoyt Pochmara" <jpochma@polyslo.UUCP>
- Archive-Name: spaceout
-
- [I didn't disappear... you did. Where are the submissions? ++bsa]
-
- #! /bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #! /bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create the files:
- # README
- # spaceout.6
- # Makefile
- # spaceout.c
- # This archive created: Sun Feb 14 19:22:43 1988
- export PATH; PATH=/bin:$PATH
- echo shar: extracting "'README'" '(1957 characters)'
- if test -f 'README'
- then
- echo shar: will not over-write existing file "'README'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'README'
- X
- X README for Spaceout
- X Version 1.1
- X 2/14/88
- X
- XWhat is Spaceout:
- X Spaceout - animated space display
- X
- X Spaceout is an X11 version of the program for Xerox XDE
- X workstations. The Xerox workstation version was done by Jef
- X Poskanzer at Versatec, A Xerox company. Spaceout displays a
- X star field, which moves as if you were traveling through
- X space ( similar to the beginning of old Star Trek tv shows).
- X
- XHow To Compile:
- X If you have X11 installed on your machine in the
- X 'standard' place all you should have to do is say
- X 'make'. Otherwise you will have to edit the makefile
- X to point where it is all kept.
- X
- XTo 'Stipple' or not 'Stipple':
- X There are two ways in which Spaceout will draw the stars on the
- X screen. Spaceout will either use stippling or copyarea to
- X draw the stars. One is of which is most likely faster on
- X you X server. I suggest you try both and see.
- X Now how to tell Spaceout which one to use. If 'STIPPLE_DRAW'
- X is defined then Spaceout use stippling, other wise
- X copyarea is used ( this define can be found near the top
- X of the spaceout.c ).
- X
- XThings To Try:
- X If you get really bored one night you might want to try playing
- X with the parameter defines at the top of spaceout.c .
- X
- X
- XHow Color works:
- X Spaceout has 6 arrays of color names in it. Spaceout
- X uses one color out of each array if the -C options is used.
- X The color names in the arrays can be a legal name for
- X XAllocNamedColor(). If the chosen color can not be allocated
- X then white is used.
- X
- XWhat Happens when Covered:
- X If Spaceout becomes fully obscured or iconifed it stops and
- X waits to become visible or un-iconified.
- X
- XWho to Bitch At:
- X If you get really stuck, you can always send mail
- X to me at
- X jpochma@polyslo.UUCP
- X
- X But I make no promises ( still in school :-) ...
- X
- X
- XMore Copyright Info:
- X Copyright (c) 1988, John H. Pochmara
- X
- X You may copy Spaceout in whole or in part as long as you don't
- X try to make money off it, or pretend that you wrote it.
- SHAR_EOF
- if test 1957 -ne "`wc -c < 'README'`"
- then
- echo shar: error transmitting "'README'" '(should have been 1957 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'spaceout.6'" '(1190 characters)'
- if test -f 'spaceout.6'
- then
- echo shar: will not over-write existing file "'spaceout.6'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'spaceout.6'
- X.TH SPACEOUT l "January 17, 1988"
- X.UC 4
- X.SH NAME
- Xspaceout \- animated space display
- X.SH SYNOPSIS
- Xspaceout [ \-fRrCc ] [ host:display ]
- X.SH DESCRIPTION
- X.PP
- X.IR Spaceout
- Xis an X11 version of the program for Xerox XDE workstations.
- XThe Xerox workstation version was done by Jef Poskanzer at
- XVersatec, A Xerox company.
- XSpaceout displays a star field, which moves as if you were
- Xtraveling through
- Xspace ( similar to the beginning of old Star Trek tv shows ).
- X.PP
- X.IR Spaceout
- Xoptions include:
- X.TP
- X.B \-f
- Xtries to fill the entire screen.
- X.TP
- X.B \-r
- X\'reverse video\'.
- X.TP
- X.B \-R
- Xruns in root window.
- X.TP
- X.B \-C
- XColor Spaceout.
- X.TP
- X.B \-c
- XThe stars move down the middle of the screen.
- X.PP
- XIf a host is not specify the environment variable DISPLAY is used.
- X.PP
- XAt this time I would like to express many thanks to Paul Shupak
- Xfor his comments and suggestions. He also wrote the random number generator
- Xthat is used
- Xin
- X.IR Spaceout .
- X.SH GIVE AWAY INFO
- X.PP
- XCopyright (c) 1988, John H. Pochmara
- X.PP
- XYou may copy Spaceout in whole or in part as long as you don't
- Xtry to make money off it, or pretend that you wrote it.
- X
- X.SH FILES
- X/usr/lib/X11/rgb*
- X.SH AUTHOR
- XJohn H. Pochmara
- X.br
- Xjpochma@polyslo.UUCP
- SHAR_EOF
- if test 1190 -ne "`wc -c < 'spaceout.6'`"
- then
- echo shar: error transmitting "'spaceout.6'" '(should have been 1190 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'Makefile'" '(336 characters)'
- if test -f 'Makefile'
- then
- echo shar: will not over-write existing file "'Makefile'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'Makefile'
- X#
- X# Makefile for Spaceout Version 1.1
- X# 2/14/88
- X#
- X# Copyright (c) 1988, John H. Pochmara
- X#
- X# You may copy Spaceout in whole or in part as long as you don't
- X# try to make money off it, or pretend that you wrote it.
- X#
- X
- XLIBS= -lX11
- XSCR = spaceout.c
- XOBJ = spaceout.o
- XCFLAGS = -O -c
- X
- Xspace: $(OBJ)
- X cc -o space $(OBJ) $(LIBS)
- X
- X$(OBJ):
- SHAR_EOF
- if test 336 -ne "`wc -c < 'Makefile'`"
- then
- echo shar: error transmitting "'Makefile'" '(should have been 336 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'spaceout.c'" '(17559 characters)'
- if test -f 'spaceout.c'
- then
- echo shar: will not over-write existing file "'spaceout.c'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'spaceout.c'
- X/*
- X *
- X * SpaceOut for X11.
- X * Version 1.1
- X *
- X * By John Pochmara (jpochma@polyslo)
- X * at Cal Poly
- X * 1988
- X *
- X * Random number generator writen by Pual Shupak.
- X *
- X * Copyright (c) 1988, John H. Pochmara
- X *
- X * You may copy Spaceout in whole or in part as long as you don't
- X * try to make money off it, or pretend that you wrote it.
- X *
- X *
- X * Original SpaceOut writen in Mesa for Xerox workstations by
- X * Jef Poskanzer at Versatec, a Xerox Company.
- X *
- X *
- X * Options:
- X * R - run in root window.
- X * r - reverse screen.
- X * f - full screen.
- X * c - all stars go right down the center of the screen.
- X * C - Color Space.
- X *
- X */
- X
- X#include <stdio.h>
- X#include <X11/Xlib.h>
- X#include <X11/Xatom.h>
- X#include <X11/Xutil.h>
- X
- X#define STIPPLE_DRAW
- X
- X#define NUM_STARS (70) /* Number of Stars */
- X#define STAR_MAXSIZE (400) /* Max size of Stars */
- X#define SPEEDZ (270) /* Speed at which Stars move forward */
- X#define MIN_VISIBLEZ (400) /* Closets you can get to a star */
- X#define MAX_VISIBLEZ (65000) /* Farthest away star you can see */
- X#define MINX (-20000) /* Min value of X cordanit */
- X#define MAXX (20000) /* Max value of X cordanit */
- X#define MINY (-20000) /* Min value of Y cordanit */
- X#define MAXY (20000) /* Max value of Y cordanit */
- X#define MINZ (30000) /* Min value of Z cordanit */
- X#define MAXZ (65535) /* Max value of Z cordanit */
- X#define SCREENZ (1500) /* Distance of projected image */
- X#define RADIUS (40) /* Size of a Star at SCREENZ */
- X#define MAG_RAD (1) /* Magnification factor of Star Radius */
- X
- X#define TRUE (1)
- X#define FALSE (0)
- X
- X#define RNDRANGE( min, max ) \
- X( ( ( (max) - (min) ) ? ( randomLong() % ( (max) - (min) ) ) : 0 ) + (min) )
- X
- X#define OBSCURED (1)
- X#define UNOBSCURED (0)
- X
- X/*
- X * Star Types.
- X */
- X#define ROUND (0)
- X#define RINGED (1)
- X#define PLANETX (2)
- X
- X/*
- X * Init. Window Postion & Dimension.
- X */
- X#define INT_WIDTH (400)
- X#define INT_HEIGHT (250)
- X#define INT_X (50)
- X#define INT_Y (50)
- X
- X
- X#define WHITE (0)
- X#define COLOR1 (1)
- X#define COLOR2 (2)
- X#define COLOR3 (3)
- X#define COLOR4 (4)
- X#define COLOR5 (5)
- X#define COLOR6 (6)
- X
- Xchar *color1[] = {
- X "pink",
- X "plum",
- X "red",
- X "IndianRed",
- X "MediumVioletRed",
- X "OrangeRed",
- X "VioletRed",
- X ""
- X};
- X
- Xchar *color2[] = {
- X "Green",
- X "DarkGreen",
- X "DarkOliveGreen",
- X "ForestGreen",
- X "LimeGreen",
- X "MediumForestGreen",
- X "MediumSeaGreen",
- X "MediumSpringGreen",
- X "PaleGreen",
- X "SeaGreen",
- X "SpringGreen",
- X "YellowGreen",
- X ""
- X};
- X
- Xchar *color3[] = {
- X "Blue",
- X "CadetBlue",
- X "CornflowerBlue",
- X "DarkSlateBlue",
- X "LightBlue",
- X "LightSteelBlue",
- X "MediumBlue",
- X "MediumSlateBlue",
- X "MidnightBlue",
- X "NavyBlue",
- X "Navy",
- X "SkyBlue",
- X "SlateBlue",
- X "SteelBlue",
- X ""
- X};
- X
- Xchar *color4[] = {
- X "Yellow",
- X "GreenYellow",
- X "Wheat",
- X "Turquoise",
- X "Sienna",
- X ""
- X};
- X
- Xchar *color5[] = {
- X "orange",
- X "Khaki",
- X "Maroon",
- X "Orchid",
- X ""
- X};
- X
- Xchar *color6[] = {
- X "violet",
- X "BlueViolet",
- X "Salmon",
- X "Gold",
- X "Goldenrod",
- X "Coral",
- X ""
- X};
- X
- X#define MAX_USED_COLORS ( 7 )
- X
- XXColor starColors[MAX_USED_COLORS];
- X
- Xtypedef struct starrec {
- X int sx,sy;
- X int x,y,z;
- X int radius;
- X int displayed;
- X int type;
- X int color;
- X} StarRec;
- X
- XStarRec Stars[NUM_STARS];
- X
- XPixmap Starpix[STAR_MAXSIZE];
- XPixmap Ringpix[STAR_MAXSIZE];
- XPixmap Xpix[STAR_MAXSIZE];
- XDisplay *dpy;
- XWindow SpaceWin;
- XWindow root;
- XWindow parent;
- XColormap cmap;
- Xint screen;
- Xint depth;
- Xint SpaceVis;
- X
- X/*
- X * Option Var.
- X *
- X */
- Xint rootwin = FALSE;
- Xint fullscreen = FALSE;
- Xint reverse = FALSE;
- Xint color = FALSE;
- Xint center = FALSE;
- Xchar *host = NULL;
- X
- Xint winwidth;
- Xint winheight;
- Xint winx;
- Xint winy;
- X
- Xstatic void init(), initwin(), initpos(), initpix(), initstar();
- Xstatic void initcolors(), setcolor();
- Xstatic void MoveStars(), DisplayStar(), NewStar(), ShowStar();
- Xstatic void DrawStar(), Newpixmap(), ProcEvent(), ReDrawStars();
- Xstatic void ReStart(), ClearStars(), usage(), prev();
- Xstatic unsigned long int randomLong();
- X
- Xmain(argc,argv)
- Xint argc;
- Xchar *argv[];
- X{
- X
- X while(--argc > 0) {
- X if(index(argv[argc],':') != 0) {
- X if(host != NULL)
- X usage();
- X else
- X host = argv[argc];
- X } else if(argv[argc][0] == '-') {
- X int i = 1;
- X
- X while(argv[argc][i] != NULL) {
- X switch(argv[argc][i]) {
- X case 'f': fullscreen = TRUE;
- X break;
- X case 'r': reverse = TRUE;
- X break;
- X case 'c': center = TRUE;
- X break;
- X case 'C': color = TRUE;
- X break;
- X case 'R': rootwin = TRUE;
- X break;
- X default: usage();
- X }
- X i++;
- X }
- X }
- X }
- X
- X if(host == NULL) {
- X if((host = (char *) getenv("DISPLAY")) == NULL) {
- X usage();
- X }
- X }
- X
- X init(host);
- X MoveStars(Stars);
- X
- X}
- X
- Xstatic void init(host)
- Xchar *host;
- X{
- X
- X initwin(host);
- X srandom((int) time(0));
- X initstar();
- X initpix();
- X
- X SpaceVis = UNOBSCURED;
- X
- X}
- X
- Xstatic void MoveStars(stars)
- XStarRec stars[];
- X{
- X int i;
- X
- X while(TRUE) {
- X ProcEvent();
- X for(i=0;i<NUM_STARS;i++) {
- X if(stars[i].z > SPEEDZ) {
- X stars[i].z = stars[i].z - SPEEDZ;
- X } else {
- X stars[i].z = MIN_VISIBLEZ/2;
- X }
- X
- X DisplayStar(&stars[i]);
- X }
- X XFlush(dpy);
- X
- X }
- X
- X}
- X
- Xstatic void DisplayStar(star)
- XStarRec *star;
- X{
- X int scrx;
- X int scry;
- X int scrradius;
- X
- X
- X if(star->z <= 0 ) star->z = 1;
- X
- X scrx = (star->x * SCREENZ) / star->z;
- X scry = (star->y * SCREENZ) / star->z;
- X scrradius = (RADIUS * SCREENZ) / star->z;
- X
- X scrx = (winwidth/2 + scrx);
- X scry = (winheight/2 + scry);
- X
- X if((scrx == star->sx)
- X && (scry == star->sy)
- X && ( scrradius == star->radius ))
- X return;
- X
- X if(star->z < MIN_VISIBLEZ) {
- X if(star->displayed == TRUE) {
- X ShowStar(star);
- X star->displayed = FALSE;
- X }
- X NewStar(star);
- X return;
- X }
- X
- X if(star->z > MAX_VISIBLEZ) {
- X if(star->displayed == TRUE) {
- X ShowStar(star);
- X star->displayed = FALSE;
- X }
- X return;
- X }
- X
- X if(star->displayed == TRUE) {
- X ShowStar(star);
- X star->displayed = FALSE;
- X }
- X
- X if((scrx > winwidth) || (scrx < -(2 * star->radius)) ||
- X (scry > winheight) || (scry < -(2 * star->radius))) {
- X NewStar(star);
- X return;
- X }
- X
- X star->sx = scrx;
- X star->sy = scry;
- X star->radius = scrradius;
- X
- X ShowStar(star);
- X star->displayed = TRUE;
- X
- X}
- X
- Xstatic void NewStar(star)
- XStarRec *star;
- X{
- X int rnd = RNDRANGE(0,100);
- X int x_range, y_range;
- X
- X star->z = RNDRANGE(MINZ,MAXZ);
- X
- X if(center != TRUE) {
- X x_range = (star->z * winwidth) / ( 2 * SCREENZ);
- X y_range = (star->z * winheight) / (2 * SCREENZ);
- X
- X star->x = RNDRANGE(-(x_range),x_range);
- X star->y = RNDRANGE(-(y_range),y_range);
- X } else {
- X star->x = 0;
- X star->y = 0;
- X }
- X
- X star->sx = (star->x * SCREENZ) / star->z;
- X star->sy = (star->y * SCREENZ) / star->z;
- X star->radius = (RADIUS * SCREENZ) / star->z;
- X star->displayed = FALSE;
- X star->color = WHITE;
- X
- X if(rnd < 3)
- X star->type = PLANETX;
- X else if(rnd < 10)
- X star->type = RINGED;
- X else {
- X star->type = ROUND;
- X star->color = RNDRANGE(0, MAX_USED_COLORS - 1);
- X }
- X
- X}
- X
- Xstatic void ShowStar(star)
- XStarRec *star;
- X{
- X
- X if(star->radius <= 0)
- X star->radius = 1;
- X
- X if(star->radius > STAR_MAXSIZE)
- X star->radius = STAR_MAXSIZE;
- X
- X switch(star->type) {
- X case RINGED:
- X if(Ringpix[star->radius] == 0) Newpixmap(star);
- X break;
- X case ROUND:
- X if(Starpix[star->radius] == 0) Newpixmap(star);
- X break;
- X case PLANETX:
- X if(Xpix[star->radius] == 0) Newpixmap(star);
- X break;
- X }
- X
- X DrawStar(star);
- X
- X}
- X
- Xstatic void DrawStar(star)
- XStarRec *star;
- X{
- X static GC gc[MAX_USED_COLORS] = { 0 };
- X int p_width = 2 * ((star->radius) * MAG_RAD);
- X int p_height = 2 * ((star->radius) * MAG_RAD);
- X Pixmap drawpix;
- X GC stargc;
- X int sx,sy;
- X int i;
- X
- X if(gc[0] == 0) {
- X
- X for(i = 0; i < MAX_USED_COLORS; i++) {
- X gc[i] = XCreateGC(dpy,SpaceWin,0,NULL);
- X XSetFunction(dpy,gc[i],GXxor);
- X XSetBackground(dpy,gc[i],BlackPixel(dpy,screen));
- X if( color == TRUE )
- X XSetForeground(dpy,gc[i],starColors[i].pixel);
- X else
- X XSetForeground(dpy,gc[i],WhitePixel(dpy,screen));
- X#ifdef STIPPLE_DRAW
- X XSetFillStyle(dpy,gc[i],FillStippled);
- X#else
- X XSetGraphicsExposures(dpy,gc[i],FALSE);
- X#endif STIPPLE_DRAW
- X }
- X }
- X
- X stargc = gc[star->color];
- X
- X switch(star->type) {
- X case ROUND:
- X drawpix = Starpix[star->radius];
- X break;
- X case RINGED:
- X drawpix = Ringpix[star->radius];
- X p_width *= 2;
- X break;
- X case PLANETX:
- X drawpix = Xpix[star->radius];
- X break;
- X default:
- X drawpix = Starpix[star->radius];
- X break;
- X
- X }
- X
- X sx = star->sx - p_width/2;
- X sy = star->sy - p_height/2;
- X
- X#ifdef STIPPLE_DRAW
- X XSetStipple(dpy,stargc,drawpix);
- X XSetTSOrigin(dpy,stargc,sx,sy);
- X XFillRectangle(dpy,SpaceWin,stargc,sx,sy,p_width,p_height);
- X#else
- X XCopyArea(dpy,drawpix,SpaceWin,stargc,0,0,p_width,p_height,sx,sy);
- X#endif STIPPLE_DRAW
- X
- X}
- X
- Xstatic void Newpixmap(star)
- XStarRec *star;
- X{
- X static GC gc = 0;
- X Pixmap pixtmp;
- X int i;
- X int p_width = 2 * ((star->radius) * MAG_RAD);
- X int p_height = 2 * ((star->radius) * MAG_RAD);
- X int r = star->radius;
- X
- X if(star->type == RINGED) {
- X p_width = 2 * p_width;
- X }
- X
- X#ifdef STIPPLE_DRAW
- X pixtmp = XCreatePixmap(dpy,SpaceWin,p_width,p_height,1);
- X#else
- X pixtmp = XCreatePixmap(dpy,SpaceWin,p_width,p_height,depth);
- X#endif STIPPLE_DRAW
- X
- X if(gc == 0) {
- X gc = XCreateGC(dpy,pixtmp,0,NULL);
- X XSetBackground(dpy,gc,BlackPixel(dpy,screen));
- X XSetForeground(dpy,gc,WhitePixel(dpy,screen));
- X XSetFillStyle(dpy,gc,FillSolid);
- X }
- X
- X switch(star->type) {
- X case ROUND:
- X XSetFunction(dpy,gc,GXxor);
- X XFillArc(dpy,pixtmp,gc,0,0,p_width,p_height,0,360*64);
- X Starpix[star->radius] = pixtmp;
- X break;
- X case RINGED:
- X XSetFunction(dpy,gc,GXxor);
- X XSetLineAttributes(dpy,gc,1,LineSolid,CapRound,JoinBevel);
- X XFillArc(dpy,pixtmp,gc,r,0,p_height,p_height,0,360*64);
- X XDrawArc(dpy,pixtmp,gc,0,r/2,p_width,p_height/2,
- X 0,360*64);
- X Ringpix[star->radius] = pixtmp;
- X break;
- X case PLANETX:
- X XSetFunction(dpy,gc,GXxor);
- X XFillArc(dpy,pixtmp,gc,0,0,p_width,p_height,0,360*64);
- X i = r/4;
- X if(i < 1) i = 1;
- X XSetLineAttributes(dpy,gc,i,LineSolid,CapRound,JoinBevel);
- X XSetFunction(dpy,gc,GXclear);
- X XDrawLine(dpy,pixtmp,gc,r/2,r/2,r+r/2,r+r/2);
- X XDrawLine(dpy,pixtmp,gc,r+r/2,r/2,r/2,r+r/2);
- X Xpix[star->radius] = pixtmp;
- X break;
- X }
- X
- X}
- X
- Xstatic void initstar()
- X{
- X int i;
- X
- X for(i=0;i<NUM_STARS;i++) {
- X NewStar(&Stars[i]);
- X }
- X
- X}
- X
- Xstatic void initpix()
- X{
- X int i;
- X
- X for(i=0;i<STAR_MAXSIZE;i++) {
- X Starpix[i] = 0;
- X Ringpix[i] = 0;
- X Xpix[i] = 0;
- X }
- X}
- X
- Xstatic void initpos()
- X{
- X if(fullscreen == TRUE) {
- X winwidth = XDisplayWidth(dpy,screen);
- X winheight = XDisplayHeight(dpy,screen);
- X winx = 0;
- X winy = 0;
- X } else {
- X winwidth = INT_WIDTH;
- X winheight = INT_HEIGHT;
- X winx = INT_X;
- X winy = INT_Y;
- X }
- X}
- X
- Xextern int XCheckTypedEvent();
- X
- Xstatic void ProcEvent()
- X{
- X XEvent ev;
- X int block = FALSE;
- X
- X while((XPending(dpy) > 0) || (block == TRUE)) {
- X XNextEvent(dpy,&ev);
- X switch(ev.type) {
- X case ReparentNotify:
- X if(ev.xreparent.window != SpaceWin ) break;
- X XSelectInput(dpy,ev.xreparent.parent,
- X StructureNotifyMask);
- X XSelectInput(dpy,parent,0);
- X parent = ev.xreparent.parent;
- X break;
- X
- X case UnmapNotify:
- X if((ev.xunmap.window != SpaceWin) &&
- X (ev.xunmap.window != parent)) break;
- X block = TRUE;
- X break;
- X
- X case VisibilityNotify:
- X if(ev.xvisibility.window != SpaceWin) break;
- X if(ev.xvisibility.state ==
- X VisibilityFullyObscured) {
- X block = TRUE;
- X break;
- X }
- X if((ev.xvisibility.state ==
- X VisibilityUnobscured) &&
- X (SpaceVis == OBSCURED)) {
- X ReStart();
- X SpaceVis = UNOBSCURED;
- X block = FALSE;
- X break;
- X }
- X if(ev.xvisibility.state ==
- X VisibilityPartiallyObscured) {
- X SpaceVis = OBSCURED;
- X block = FALSE;
- X }
- X break;
- X
- X case Expose:
- X ReStart();
- X block = FALSE;
- X break;
- X
- X case MapNotify:
- X if((ev.xmap.window != SpaceWin) &&
- X (ev.xmap.window != parent)) break;
- X ReStart();
- X block = FALSE;
- X break;
- X
- X case ConfigureNotify:
- X if(ev.xconfigure.window != SpaceWin) break;
- X ReStart();
- X if((winwidth == ev.xconfigure.width) &&
- X (winheight == ev.xconfigure.height))
- X break;
- X winwidth = ev.xconfigure.width;
- X winheight = ev.xconfigure.height;
- X ReDrawStars();
- X block = FALSE;
- X break;
- X
- X default:
- X break;
- X }
- X }
- X}
- X
- Xstatic void ReDrawStars()
- X{
- X int i;
- X
- X for(i=0;i<NUM_STARS;i++) {
- X DisplayStar(&Stars[i]);
- X }
- X}
- X
- Xstatic void ReStart()
- X{
- X XClearWindow(dpy,SpaceWin);
- X XSync(dpy, 0);
- X ClearStars();
- X}
- X
- Xstatic void ClearStars()
- X{
- X int i;
- X
- X for(i=0;i<NUM_STARS;i++) {
- X Stars[i].displayed = FALSE;
- X }
- X}
- X
- Xstatic void initcolors()
- X{
- X unsigned long backgrd;
- X
- X if( reverse == TRUE )
- X backgrd = WhitePixel(dpy,screen);
- X else
- X backgrd = BlackPixel(dpy,screen);
- X
- X starColors[WHITE].pixel = WhitePixel(dpy,screen);
- X
- X setcolor(color1,&starColors[COLOR1]);
- X starColors[COLOR1].pixel ^= backgrd;
- X
- X setcolor(color2,&starColors[COLOR2]);
- X starColors[COLOR2].pixel ^= backgrd;
- X
- X setcolor(color3,&starColors[COLOR3]);
- X starColors[COLOR3].pixel ^= backgrd;
- X
- X setcolor(color4,&starColors[COLOR4]);
- X starColors[COLOR4].pixel ^= backgrd;
- X
- X setcolor(color5,&starColors[COLOR5]);
- X starColors[COLOR5].pixel ^= backgrd;
- X
- X setcolor(color6,&starColors[COLOR6]);
- X starColors[COLOR6].pixel ^= backgrd;
- X
- X
- X}
- X
- Xstatic void setcolor(cnames,xcolor)
- Xchar *cnames[];
- XXColor *xcolor;
- X{
- X int i = 0;
- X int count = 0;
- X XColor ecolor;
- X
- X while( *cnames[count] != NULL ) {
- X count++;
- X }
- X
- X i = RNDRANGE(0,count-1);
- X
- X if( XAllocNamedColor(dpy,cmap,cnames[i],xcolor,&ecolor) > 0)
- X return;
- X else {
- X i = 0;
- X
- X while( *cnames[i] != NULL ) {
- X if( XAllocNamedColor(dpy,cmap,cnames[i],
- X xcolor,&ecolor) > 0)
- X return;
- X else
- X continue;
- X }
- X }
- X
- X xcolor->pixel = starColors[WHITE].pixel;
- X}
- X
- Xstatic void initwin(hostmon)
- Xchar *hostmon;
- X{
- X XSetWindowAttributes attr;
- X char *name;
- X
- X if((dpy = XOpenDisplay(hostmon)) == NULL) {
- X fprintf(stderr,"Connection not made.\n");
- X exit(1);
- X }
- X
- X screen = DefaultScreen(dpy);
- X cmap = DefaultColormap(dpy,screen);
- X parent = root = RootWindow(dpy,screen);
- X depth = DefaultDepth(dpy,screen);
- X
- X if( color == TRUE )
- X initcolors();
- X
- X initpos();
- X
- X XSelectInput(dpy,root,SubstructureNotifyMask);
- X
- X attr.event_mask = StructureNotifyMask
- X | SubstructureNotifyMask
- X | VisibilityChangeMask
- X | ExposureMask;
- X
- X if(reverse == TRUE)
- X attr.background_pixel = WhitePixel(dpy,screen);
- X else
- X attr.background_pixel = BlackPixel(dpy,screen);
- X
- X if(rootwin == TRUE) {
- X SpaceWin = root;
- X XChangeWindowAttributes(dpy,SpaceWin,
- X CWEventMask|CWBackPixel,&attr);
- X } else {
- X
- X SpaceWin = XCreateWindow(dpy,root,winx,winy,winwidth,winheight,
- X 0,depth,InputOutput,
- X DefaultVisual(dpy,screen),
- X CWEventMask|CWBackPixel,&attr);
- X
- X if( color == TRUE )
- X name = "Color SpaceOut";
- X else
- X name = "SpaceOut";
- X
- X XChangeProperty(dpy,SpaceWin,XA_WM_NAME,XA_STRING,8,
- X PropModeReplace,name,strlen(name));
- X XMapWindow(dpy,SpaceWin);
- X }
- X
- X XClearWindow(dpy,SpaceWin);
- X XSync(dpy, 0);
- X
- X}
- X
- Xstatic void usage()
- X{
- X fprintf(stderr,"usage: space [host:screen] [-frCc]\n");
- X exit(0);
- X}
- X
- Xstatic int randomBit()
- X{
- Xregister unsigned long int tmp ;
- Xstatic unsigned long int state = 0x10 ;
- X
- X/* Linear Feedback Shift Register
- X * Length = 31 Bits
- X * Taps at 3 & 31
- X * Period = ( 2 ** 31 ) - 1
- X */
- Xtmp = state ;
- X/* Next State */
- Xstate = ( ( ( tmp << 2 ) ^ ( tmp << 30 ) ) & 0x80000000 ) | ( tmp >> 1 ) ;
- X
- Xreturn tmp >> 31 ;
- X}
- X
- X/* Random Number Generator State Variables */
- Xstatic unsigned long int lastRandom = 1 ;
- Xstatic unsigned long int oldRandom ;
- X
- Xstatic unsigned long int randomLong()
- X{
- Xregister unsigned long int tmpA ;
- Xregister unsigned long int tmpB ;
- X
- Xregister unsigned long int tmpH ;
- Xregister unsigned long int tmpM1 ;
- Xregister unsigned long int tmpM2 ;
- Xregister unsigned long int tmpL ;
- X
- Xregister long int SumOldL ;
- Xregister long int SumOldH ;
- Xregister long int SumLastL ;
- Xregister long int SumLastH ;
- X
- X/*
- X * Modular Congruence Method
- X * Period >= ( 2 ** 31 ) - 1
- X * X(n) =
- X * ( 271,828,183 * X(n-1) - 314,159,269 * X(n-2) ) mod ( ( 2 ** 31 ) - 1 )
- X * = ( 0x1033C4D7 * X(n-1) - 0x12B9B0A5 * X(n-2) ) mod ( ( 2 ** 31 ) - 1 )
- X * To Avoid OverFlow USE:
- X * ( ( x1 * ( 2 ** 16 ) ) + x2 ) * ( ( y1 * ( 2 ** 15 ) ) + y2 ) =
- X * ( x1 * y1 * ( 2 ** 31 ) )
- X * + ( x2 * y1 * ( 2 ** 15 ) )
- X * + ( x1 * y2 * ( 2 ** 16 ) )
- X * + ( x2 * y2 )
- X * NOTE:
- X * 0x1033C4D7 == ( 0x2067 * 0x08000 ) + 0x44D7
- X * == ( 0x1033 * 0x10000 ) + 0xC4D7
- X * 0x12B9B0A5 == ( 0x2573 * 0x08000 ) + 0x30A5
- X * == ( 0x12B9 * 0x10000 ) + 0xB0A5
- X */
- XtmpA = oldRandom ;
- X
- XtmpB = tmpA & 0xFFFF ; /* Low Order 16 Bits of X(n-2) */
- XtmpM1 = tmpB * 0x2573 ; /* Offset 16 Bits */
- XtmpL = tmpB * 0x30A5 ; /* Offset 0 Bits */
- XtmpA >>= 16 ; /* High Order 15 Bits of X(n-2)
- XtmpH = tmpA * 0x2573 ; /* Offset 31 Bits */
- XtmpM2 = tmpA * 0x30A5 ; /* Offset 15 Bits */
- X/* Now Sum Them */
- XSumOldL = tmpL & 0x7FFF ;
- XtmpA = ( tmpL >> 15 ) + tmpM2 + ( tmpM1 << 1 ) ;
- XSumOldL |= ( ( tmpA << 15 ) & 0x7FFF8000 ) ; /* Bottom 31 Bits */
- XSumOldH = ( ( tmpA >> 16 ) + tmpH ) ; /* Top 31 Bits */
- X
- XoldRandom = tmpA = lastRandom ;
- X
- XtmpB = tmpA & 0xFFFF ; /* Low Order 16 Bits of X(n-1) */
- XtmpM1 = tmpB * 0x2067 ; /* Offset 15 bits */
- XtmpL = tmpB * 0x44D7 ; /* Offset 0 bits */
- XtmpA >>= 16 ; /* High Order 15 Bits of X(n-1)*/
- XtmpH = tmpA * 0x2067 ; /* Offset 31 bits */
- XtmpM2 = tmpA * 0x44D7 ; /* Offset 16 bits */
- X/* Now Sum Them */
- XSumLastL = tmpL & 0x7FFF ;
- XtmpA = ( tmpL >> 15 ) + tmpM2 + ( tmpM1 << 1 ) ;
- XSumLastL |= ( ( tmpA << 15 ) & 0x7FFF8000 ) ; /* Bottom 31 Bits */
- XSumLastH = ( ( tmpA >> 16 ) + tmpH ) ; /* Top 31 Bits */
- X
- XtmpA = SumLastH - SumOldH ;
- XtmpB = SumLastL - SumOldL ;
- Xif ( SumLastL < SumOldL ) {
- X tmpB &= 0x7FFFFFFF ;
- X tmpA-- ;
- X}
- X
- Xreturn lastRandom = ( ( tmpA + tmpB ) & 0x7FFFFFFF ) ;
- X}
- X
- Xstatic void prev(ev)
- XXEvent *ev;
- X{
- X printf("event->type: %d\n",ev->type);
- X}
- SHAR_EOF
- if test 17559 -ne "`wc -c < 'spaceout.c'`"
- then
- echo shar: error transmitting "'spaceout.c'" '(should have been 17559 characters)'
- fi
- fi # end of overwriting check
- # End of shell archive
- exit 0
-